#!/usr/bin/env python
# -*- coding: utf-8 

from BeautifulSoup import BeautifulSoup
import urllib
import urllib2

class htmlRetrieving:
    global soup
    global fileOpened
    def __init__(self, URLToFetch):
        global soup
        global fileOpened
        fileOpened = False
        
        try:
            file = urllib.urlopen(URLToFetch)
            soup = BeautifulSoup(''.join(file.read()))
            fileOpened = True
        except:
            fileOpened = False
            pass
    
    def getFileOpened(self):
        global fileOpened
        return  fileOpened
    
    def countH1(self):
    	global soup
    	return  len(soup('h1'))
    
    def countH2(self):
        global soup
        return  len(soup('h21'))

    def countH3(self):
        global soup
        return  len(soup('h3'))

    def countDiv(self):
        global soup
        return  len(soup('div'))

    def countP(self):
        global soup
        return  len(soup('p'))

    def countUl(self):
        global soup
        return  len(soup('ul'))

    def countOl(self):
        global soup
        return  len(soup('ol'))


def getFileOpened(self):
    global fileOpened
    return  fileOpened

